package com.zhucan.account.infrastructure.exception.advice;

import com.zhucan.account.infrastructure.exception.AccountNotAccessException;
import com.zhucan.account.application.query.dto.ResultDTO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

/**
 * author: zhuCan
 * date: 2020/8/6 15:18
 * description:
 */
@RestControllerAdvice
public class AccountNotAccessExceptionAdvice {

  @ExceptionHandler(AccountNotAccessException.class)
  @ResponseStatus(HttpStatus.FORBIDDEN)
  public ResultDTO handler(HttpServletResponse response, AccountNotAccessException e) {

    return ResultDTO.builder().code(HttpStatus.FORBIDDEN.value())
        .msg(e.getLocalizedMessage())
        .build();
  }
}
